//
//  LicensedPatientVC.m
//  Doctors
//
//  Created by 王森 on 16/4/13.
//  Copyright © 2016年 王森. All rights reserved.
//

#import "LicensedPatientVC.h"
#import "PatientTableViewCell.h"
#import "PatientDetailVIewController.h"
@interface LicensedPatientVC ()

@end

@implementation LicensedPatientVC

- (void)viewDidLoad {
    [super viewDidLoad];
      [self setTextTitleViewWithFrame:CGRectMake(0, 0, 60, 20) title:@"病患管理" fontSize:18];

    [self customTableView];
    
    __weak typeof(self)weakSelf=self;
   
    [weakSelf requestData];


    [self setTableHeaderRefresh:^{
        [weakSelf.dataArray removeAllObjects];
        
        weakSelf.page=1;
        
        [weakSelf requestData];
   
    }];
    
    [self setFooterfresh:^{
        weakSelf.page++;
        [weakSelf requestData];

        
    }];
    
    
    [self registerNib:@"PatientTableViewCell"];
    
    

    
    
    // Do any additional setup after loading the view from its nib.
}

-(void)requestData{
    [self addProgressHUD];
    


    [self requestApiWithUrl:@"/order/queryMedicalReceiptList" dictionary:@{@"artisanId":[self getArtisanId],@"size":@"10",@"page":[NSString stringWithFormat:@"%d",self.page]} isCache:NO success:^(id responseObject) {
        
        [self removeStatuslable];
        

        NSLog(@"%@",responseObject);
        
        
        NSArray *array=responseObject[@"orderList"];
        if (array.count==0) {
            self.page--;
            
        }
        for (NSDictionary *dic in array) {
            
            LicensedOrderModel *model=[[LicensedOrderModel alloc]initWithDic:dic];
            NSLog(@"ID:%@",model.id);
            
            [self.dataArray addObject:model];
            
        }
        
        [self.tableview reloadData];
        

        
        [self endReFresh];
        
        
    } faild:^(NSError *error) {
        self.page--;
        
        [self endReFresh];
        
    }];
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        PatientTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PatientTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
  
    if (self.dataArray.count!=0) {
        [cell patientVCM:self.dataArray[indexPath.row]];

    }
    
//    __weak typeof(self)weakSef=self;
    
   
    
    return cell;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.dataArray.count;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
           return 123;
        
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
//        __weak typeof(self)weakSelf=self;
    
    LicensedOrderModel *model=self.dataArray[indexPath.row];
    NSString *stringID=[NSString stringWithFormat:@"%@",model.id];
    
    
    NSLog(@"%@",stringID);
    

    ALLOC(PatientDetailVIewController, view);
    view.hidesBottomBarWhenPushed=YES;
    view.ID=stringID;
    
    [self pushNextViewController:view];
    NSLog(@"请重写方法");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
